import request from '@/utils/request'
// import { useUserStore } from '@/pinia/modules/user'
// import FileSaver from 'file-saver'
import qs from 'qs'

// 登陆
export const login = data => {
  return request({
    url: '/auth/login',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data)
  })
}

// 检查密码
export const check_password = params => {
  return request({
    url: '/user/checkPwd',
    method: 'get',
    params
  })
}

// 获取快捷语
export const get_approve_default = params => {
  return request({
    url: '/quickPhrases',
    method: 'get',
    params
  })
}

// 获取用户信息
export const get_user = params => {
  return request({
    url: '/user/getCurrentUser',
    method: 'get',
    params
  })
}

// 获取菜单路由
export const get_menus = params => {
  return request({
    url: '/auth/resources',
    method: 'get',
    params
  })
}

// 获取字典
export const get_dict_code = (data) => {
  return request({
    url: '/auth/dict/tree',
    method: 'get',
    params: data
  })
}

// 获取区划
export const gerAreaByCode = (code) => {
  return request({
    url: `/area/nextArea/${code}`,
    method: 'get'
  })
}

// 上传附件
export const upload_file = data => {
  return request({
    url: `/file/uploadMaterials`,
    method: 'post',
    data
  })
}

// 退出登陆
export const login_out = () => {
  return request({
    url: `/auth/logout`,
    method: 'get'
  })
}

// 获取当前用户下拉机构
export const get_org_by_user = params => {
  return request({
    url: `/organization/currentOrg`,
    method: 'get',
    params
  })
}

// 选择机构进行登录
export const select_org_login = data => {
  return request({
    url: `/organization/relateUserOrg`,
    method: 'post',
    data
  })
}

// 获取机构下拉
export const get_org_page_list = params => {
  return request({
    url: `/organization`,
    method: 'get',
    params
  })
}

// 获取多选下拉选项
export const get_multiple_options_list = (url,params) => {
  return request({
    url,
    method: 'get',
    params
  })
}

// 系统参数
export const set_params = (params) => {
  return request({
    url:'auth/listParam',
    method: 'get',
    params
  })
}


// 获取机构类型
export const get_org_type_list = params => {
  return request({
    url:'/orgType/list',
    method: 'get',
    params
  })
}

// 获取机构
export const get_org_options = params => {
  return request({
    url:'/organization',
    method: 'get',
    params
  })
}

// 获取验证码
export const get_captcha = params => {
  return request({
    url:'/auth/captcha',
    method: 'get',
    params
  })
}

// 获取机构类型
export const get_org_type_dict = params => {
  return request({
    url:'/orgType/alllist',
    method: 'get',
    params
  })
}

// 修改密码
export function update_pwd(data) {
  return request({
    url: '/user/pwd',
    method: 'put',
    data
  })
}

// 根据文件id获取base64文件流
export function get_base64_file(id) {
  return request({
    url: `/file/${id}`,
    method: 'get'
  })
}

// 导出
export const downLoad = (params,url) => {
  return request({
    url:`${url}`,
    method: 'get',
    params,
    responseType: 'blob'
  })
}

// 我的代办
export const getWaitList = (params,url) => {
  return request({
    url:`/myAgent/waitList`,
    method: 'get',
    params
  })
}

// 代办处理
export const waitHandle = (data) => {
  return request({
    url:`/myAgent/handle`,
    method: 'put',
    data
  })
}

/* 资产监管审批公共接口 */
// 审核
export const approve_submit = (url,type,data) => {
  return request({
    url,
    method: type,
    data
  })
}

// 审核节点
export const get_approve_records = processInstanceId => {
  return request({
    url: `/process/getProcessNodesByProcessInstanceId/${processInstanceId}`,
    method: 'get'
  })
}

// 审核历史记录
export const get_approve_history = processInstanceId => {
  return request({
    url: `/process/processHis/${processInstanceId}`,
    method: 'get'
  })
}

// 附件审批接口-审批
export const submit_approve_remark = data => {
  return request({
    url: `/assetSupervisionProposal`,
    method: 'post',
    data
  })
}

// 附件审批接口-查看
export const look_approve_remark = params => {
  return request({
    url: `/assetSupervisionProposal/list`,
    method: 'get',
    params
  })
}

// 获取用户自己及下级区划
export const get_user_area = params => {
  return request({
    url: `/area/list`,
    method: 'get',
    params
  })
}
// 获取城市下 所有的机构
export const get_city_org = params => {
  return request({
    url: `/organization/orgList`,
    method: 'get',
    params:{
      ...params,
      orgType:1
    }
  })
}

// 获取当前附件类型是否存在审批意见
export const get_file_approval_show = params => {
  return request({
    url: `assetSupervisionProposal/getHasApproval`,
    method: 'get',
    params
  })
}

// 选择机构
export const getSubOrg = params => { 
  // return request({
  //   url: `/organization/sub-org`,
  //   method: 'get',
  //   params
  // })
  return request({
    url: `/organization/sub-org-v2`,
    method: 'get',
    params
  })
}

// 下载任务count
export const get_xzrw_count = (id) => {
  return request({
    url: `/downloaders/doing-count`,
    method: 'get'
  })
}

// // 获取地区区划
// export const gerAreaByCode = data => {
//   return request({
//     url: `${apiConfig.baseApi}/areas/next-children/${data}`,
//     method: 'get'
//   })
// }
// 获取地区区划
export const getAreaInfo = data => {
  return request({
    url: `/areas/${data}`,
    method: 'get'
  })
}